package com.zsl.picture.util;

import java.util.HashMap;

/**
 * @author zsl
 * @date 2022/1/17
 * @email 154777150@qq.com
 */
public class R extends HashMap<String,Object> {
    public static final String CODE="code";

    public static final String MSG="msg";

    public R(){
        put(CODE,200);
        put(MSG,"success");
    }

    public static R ok(){
        return new R();
    }

    public static R ok(String msg){
        return (R) new R().put(MSG,msg);
    }

    public static R error(){
        R r = new R();
        r.put(CODE,500);
        r.put(MSG,"服务器错误");
        return r;
    }

    public static R error(String msg){
        R r = R.error();
        r.put(MSG,msg);
        return r;
    }

    @Override
    public R put(String key, Object object){
        super.put(key,object);
        return this;
    }

    public int getCode(){
        return Integer.parseInt(this.get(CODE).toString());
    }

    public String getMsg(){
        return this.get(MSG).toString();
    }
}
